﻿using System;
using MM.Data.DataContexts;

namespace MM.Services
{
    public class BaseService : IDisposable
    {
        public MyMoneyContext MyMoneyContext { get; set; }

        public BaseService()
        {
            InitConnectionString();
        }

        public void Dispose()
        {
            Commit();
            if (MyMoneyContext != null)
            {
                MyMoneyContext.Dispose();
            }
        }

        private void InitConnectionString()
        {
            MyMoneyContext = new MyMoneyContext();
        }

        public void Commit()
        {
            if (MyMoneyContext != null)
            {
                MyMoneyContext.SaveChanges();
            }
        }
    }
}